(function() {
	var e = /[?&]([^=&?]+)=([^=&?]*)/g,
		r = null;
	window.params = {};
	while(r = e.exec(location.search))
		window.params[r[1]] = r[2];

	var myApp = angular.module('myApp');

	myApp.controller("mainController", function(mtAjax, $rootScope, $scope, $log, reqDataByAjax, mtShowModal, myTableOption,mtRefreshTable,$timeout,$filter) {
		$scope.someUrl='/scheduling/html/pub/main/index.html';
		var nowdate=new Date();
		//获取当前日期并格式化
		$scope.nowDate=$filter('date')(nowdate, "yyyy年M月d日");

		// 首页跳转情况下，选中并展开节点
		if(window.params["redirect_menu"] && window.params["redirect_menu"] != ""){
			$timeout(function(){
				var paramsURI = location.search.substring(15);
				var menus = angular.element("a[ng-click*='forwardTo']");
				angular.forEach(menus, function(value, key){
					var menuUri = angular.element(value).attr("data-uri");
					if(menuUri==paramsURI){
						angular.element(value).click();
					}
				});

			}, 2000);
		}

        //保存审核状态
        $scope.forwardTo = function (uri, $event) {
            //var test = angular.element($event.currentTarget);
            //angular.element($event.currentTarget).addClass('active');

            // TODO 移除选中
            console.log($($event.target).parent().parent().prev().eq(0));
			angular.element($event.currentTarget).parent().parent('ul').find('li').removeClass("hover");
          	$($event.target).parent().eq(0).addClass('hover');
            angular.element($event.currentTarget).parent().parent('ul').find('li').removeClass("current-page");
            angular.element($event.currentTarget).parent().addClass("current-page");
            //angular.element($event.currentTarget).parent().addClass("current-page").parent('ul').parent().addClass('active');
            $scope.someUrl = uri;

        };

//
// 		reqDataByAjax("/bdzh/api/pub/homeframe/homeframe/unReadNumber").then(function(data) {
// 			$scope.noticeNumber = data[0][0].cc;
// 			$scope.remindNumber = data[1][0].cc;
// 			$scope.unReadNewsNumber = data[2][0].cc;
//
// 			if($scope.noticeNumber == 0){
// 				$('#tonggao').hide()
// 			}
// 			if($scope.remindNumber == 0){
// 				$('#tixing').hide()
// 			}
// 			if($scope.unReadNewsNumber == 0){
// 				$('#weiduxiaoxi').hide()
// 			}
// 		});
//
//
// 		var noticeOption = {
// 			show: true,
// 			backdrop: 'static'
// 		};
//
// 		reqDataByAjax("/bdzh/api/pub/homeframe/homeframe/findBeginPass").then(function(data) {
// 			$scope.beginPass = data[0][0];
//
// 			if($scope.beginPass.pw_type == 0) {
// 				mtShowModal('#changeInitialPassword', noticeOption);
// 			} else if ($scope.beginPass.pw_type != 0 && $scope.noticeNumber != 0){
// //				if(!window.params["redirect_menu"] || window.params["redirect_menu"] == ""){
// //
// //				}
// 				mtShowModal('#noticeRemindNews', noticeOption);
// 			}
// 		});
//
//
// 		$scope.tztg = function() {
// 			mtShowModal('#noticeRemindNews', noticeOption);
// 			mtRefreshTable('#noticeTable');
// 		};
//

//
// 		//      $scope.news = function($event){
// 		//      	$(".tonggao").removeClass("tonggao");
// 		//      }

	});

	//通告信息列表
	myApp.controller("noticeController", function($compile,$rootScope, $scope, $log, reqDataByAjax, mtShowModal, noticeTableOption,mtRefreshTable) {
		
		//TAB显示之后，调整表格大小
		$scope.$on("show.bs.tab", function(event, element, targe) {
			//如果要调整刷新列表，那么在下方定义显示刷新的是哪个列表
			if(targe.is("#noticeTable")) {
				//进行刷新 根据需要显示的列表的id
				$scope.$root.$broadcast("resize.table", "#noticeTable");
			}
		});
		//赋值
		$scope.noticeOption = noticeTableOption;
		
		$scope.noticeOption.rowCallback = function(row, data, index) {
			$compile(angular.element(row))($scope);
		};
		//
		$scope.noticeOption.ajax = ajax;

		function ajax(data, callback, settings) {

			reqDataByAjax("/bdzh/api/pub/homeframe/homeframe/getNoticeTable",data).then(function(ret) {
				//定义一个callback，返回以下结果
				callback({
					"data": ret[0],
					"draw": data.draw,
					"recordsTotal": ret[1][0].recordsTotal,
					"recordsFiltered": ret[2][0].recordsFiltered
				});
			});
		};
		
		//点击查看按钮刷新当前的列表，为了实时的刷新列表中数据的状态，下方的此方法同理
		$scope.refreshTable = function(){
			mtRefreshTable('#noticeTable');
		};
	});

	//提醒信息列表
	myApp.controller("remindController", function($compile,mtRefreshTable,$rootScope, $scope, $log, reqDataByAjax, mtShowModal, myTableOption) {

		//TAB显示之后，调整表格大小
		$scope.$on("show.bs.tab", function(event, element, targe) {
			//如果要调整刷新列表，那么在下方定义显示刷新的是哪个列表
			if(targe.is("#remindTable")) {
				//进行刷新 根据需要显示的列表的id
				$scope.$root.$broadcast("resize.table", "#remindTable");
			}
		});
		//赋值
		$scope.remindOption = myTableOption;
		
		$scope.remindOption.rowCallback = function(row, data, index) {
			$compile(angular.element(row))($scope);
		};
		
		//
		$scope.remindOption.ajax = ajax;

		function ajax(data, callback, settings) {

			reqDataByAjax("/bdzh/api/pub/homeframe/homeframe/getRemindTable",data).then(function(ret) {
				//定义一个callback，返回以下结果
				callback({
					"data": ret[0],
					"draw": data.draw,
					"recordsTotal": ret[1][0].recordsTotal,
					"recordsFiltered": ret[2][0].recordsFiltered
				});
			});
		};
		
		$scope.refreshTable = function(){
			mtRefreshTable('#remindTable');
		};
	});

	//全部消息信息列表
	myApp.controller("allMessageController", function($compile,$rootScope, $scope, $log, reqDataByAjax, mtShowModal, allMessageTableOption,mtRefreshTable) {

		//TAB显示之后，调整表格大小
		$scope.$on("show.bs.tab", function(event, element, targe) {
			//如果要调整刷新列表，那么在下方定义显示刷新的是哪个列表
			if(targe.is("#allMessageTable")) {
				//进行刷新 根据需要显示的列表的id
				$scope.$root.$broadcast("resize.table", "#allMessageTable");
			}
		});
		//赋值
		$scope.allMessageOption = allMessageTableOption;
		
		$scope.allMessageOption.rowCallback = function(row, data, index) {
			$compile(angular.element(row))($scope);
		};
		
		//
		$scope.allMessageOption.ajax = ajax;

		function ajax(data, callback, settings) {

			reqDataByAjax("/bdzh/api/pub/homeframe/homeframe/getAllMessageTable",data).then(function(ret) {
				//定义一个callback，返回以下结果
				callback({
					"data": ret[0],
					"draw": data.draw,
					"recordsTotal": ret[1][0].recordsTotal,
					"recordsFiltered": ret[2][0].recordsFiltered
				});
			});
		};
		
		$scope.refreshTable = function(){
			mtRefreshTable('#allMessageTable');
		};
	});

	//已读消息信息列表
	myApp.controller("readedMessageController", function($compile,$rootScope, $scope, $log, reqDataByAjax, mtShowModal, readedMessageTableOption,mtRefreshTable) {

		//TAB显示之后，调整表格大小
		$scope.$on("show.bs.tab", function(event, element, targe) {
			//如果要调整刷新列表，那么在下方定义显示刷新的是哪个列表
			if(targe.is("#readedMessageTable")) {
				//进行刷新 根据需要显示的列表的id
				$scope.$root.$broadcast("resize.table", "#readedMessageTable");
			}
		});
		//赋值
		$scope.readedMessageOption = readedMessageTableOption;
		
		$scope.readedMessageOption.rowCallback = function(row, data, index) {
			$compile(angular.element(row))($scope);
		};
		
		//
		$scope.readedMessageOption.ajax = ajax;

		function ajax(data, callback, settings) {

			reqDataByAjax("/bdzh/api/pub/homeframe/homeframe/getreadedMessageTable",data).then(function(ret) {
				//定义一个callback，返回以下结果
				callback({
					"data": ret[0],
					"draw": data.draw,
					"recordsTotal": ret[1][0].recordsTotal,
					"recordsFiltered": ret[2][0].recordsFiltered
				});
			});
		};
		
		$scope.refreshTable = function(){
			mtRefreshTable('#readedMessageTable');
		};
	});

	//未读消息信息列表
	myApp.controller("unReadMessageController", function($compile,$rootScope, $scope, $log, reqDataByAjax, mtShowModal, unReadMessageTableOption,mtRefreshTable) {

		//TAB显示之后，调整表格大小
		$scope.$on("show.bs.tab", function(event, element, targe) {
			//如果要调整刷新列表，那么在下方定义显示刷新的是哪个列表
			if(targe.is("#unReadMessageTable")) {
				//进行刷新 根据需要显示的列表的id
				$scope.$root.$broadcast("resize.table", "#unReadMessageTable");
			}
		});
		//赋值
		$scope.unReadMessageOption = unReadMessageTableOption;
		
		$scope.unReadMessageOption.rowCallback = function(row, data, index) {
			$compile(angular.element(row))($scope);
		};
		
		//
		$scope.unReadMessageOption.ajax = ajax;

		function ajax(data, callback, settings) {

			reqDataByAjax("/bdzh/api/pub/homeframe/homeframe/getunReadMessageTable",data).then(function(ret) {
				//定义一个callback，返回以下结果
				callback({
					"data": ret[0],
					"draw": data.draw,
					"recordsTotal": ret[1][0].recordsTotal,
					"recordsFiltered": ret[2][0].recordsFiltered
				});
			});
		};
		
		$scope.refreshTable = function(){
			mtRefreshTable('#unReadMessageTable');
		};
	});

})();